using System;
using System.Windows.Media.Media3D;

using NewtonDynamics;

namespace NewtonDynamics
{
	public partial class CCollision
	{
		#region Members

		protected IntPtr m_Handle;
		internal IntPtr Handle { get { return m_Handle; } }

		protected CWorld m_World;
		public CWorld World { get { return m_World; } }

		#endregion


		#region Constructor

		public CCollision(CWorld pWorld)
		{
			m_World = pWorld;
		}

		#endregion


		#region Methods

		public void Release()
		{
			Newton.NewtonReleaseCollision(m_World.Handle, m_Handle);
			CHashTables.Collision.Remove(m_Handle);
		}

		public void MakeUnique()
		{
			Newton.NewtonCollisionMakeUnique(m_World.Handle, m_Handle);
		}

		public CCollisionConvexPrimitives CreateConvexHullModifier()
		{
			CCollisionConvexPrimitives aCollision = new CCollisionConvexPrimitives(m_World);
			aCollision.m_Handle = Newton.NewtonCreateConvexHullModifier(m_World.Handle, m_Handle);

			CHashTables.Collision.Add(aCollision.m_Handle, aCollision);

			return aCollision;
		}

		#endregion


		#region Properties

		public Matrix3D ConvexHullModifierMatrix
		{
			get
			{
				NewtonMatrix aMatrix = new NewtonMatrix(Matrix3D.Identity);
				Newton.NewtonConvexHullModifierGetMatrix(m_Handle, aMatrix.NWMatrix);
				return aMatrix.ToDirectX();
			}

			set
			{
				NewtonMatrix aMatrix = new NewtonMatrix(value);
				Newton.NewtonConvexHullModifierSetMatrix(m_Handle, aMatrix.NWMatrix);
			}
		}

		#endregion
	}
}

